package com.hongxun.design.sqlite.dao;

import android.content.Context;
import android.util.Log;

import com.hongxun.design.sqlite.bean.Bj;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/5/4.
 */

public class BjDao extends BaseDao<Bj> {

    public BjDao(Context context) {
        super(context);
    }

    public List<Bj> getBjList(String proId, String bxId) {
        List<Bj> list = new ArrayList<>();
        try {
            list = dao.queryBuilder().where().eq("proId", proId).and().eq("bx_id", bxId).query();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;

    }

    public void deleteByBxId(String proId, String bxId) {
        try {
//            List<Bj> list = dao.deleteBuilder()
//                    .where().eq("proId", proId)
//                    .and().eq("bx_id", bxId)
//                    .query();
//            Log.e("delete", list.toString());
            //1
//            dao.delete(dao.queryForAll());
            //2
            List<Bj> list2 = dao.queryBuilder().where().eq("proId", proId).and().eq("bx_id", bxId).query();
            if (list2 != null) {
                for (Bj bj : list2) {
                    delete(bj);
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
